package com.ndp.fb.walle.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ndp.fb.model.fbagent.result.productfeed.FBProductCatalog;
import com.ndp.fb.rdb.api.ProductCatalogRdbService;
import com.ndp.fb.rdb.model.ProductCatalog;
import com.ndp.fb.rdb.model.User;
import com.ndp.fb.walle.business.ProductCatalogService;
import com.ndp.fb.walle.model.vo.productcatalog.BindProductCatalogVoParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by jacky.cheng on 2016/5/17.
 */
@RestController
@RequestMapping("catalog")
public class ProductCatalogController {

    @Reference
    private ProductCatalogRdbService productCatalogRdbService;

    @Autowired
    private ProductCatalogService productCatalogService;

    //返回所有可用的
    @RequestMapping("all")
    public List<FBProductCatalog> findAll(Long feedId,HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return productCatalogService.getFbAll(user,feedId);
    }

    @RequestMapping("byFeed")
    public List<ProductCatalog> findByFeed(Long feedId) {
        return productCatalogService.findByFeed(feedId);
    }

    @RequestMapping("bind")
    public Boolean bind(@RequestBody(required = true) BindProductCatalogVoParam param ,HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return  productCatalogService.bind(param.getWefeedId(), param.getCatalogs(),user.getTicket());
    }

}
